package hello.controller;

import hello.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * Created by Intellige Idea.
 * Author hiberk
 * Date 2017/5/22 17:07
 */
public class MybatisTest {

    public static void main(String[] args) {
        //通过xml创建SQLSession实例
        String resource = "Configuration.xml";
        Reader reader = null;
        try {
            reader = Resources.getResourceAsReader(resource);
            SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
            SqlSession sqlSession = sqlMapper.openSession(true);
            User user = (User)sqlSession.selectOne("hello.mappers.UserMapper.getUser",1);
//            UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
//            Users user = userMapper.getById(1);
            user.setUserName("metric");
            user.setAliase("metro");
            user.setAge((byte)22);
//            sqlSession.insert("hello.mappers.UserMapper.addUser", user);
            System.out.println(user);
            sqlSession.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

        }

    }


}
